const fs=require('fs');
const path=require('path')
const LCPlugin = require('../libs/LCPlugin');
class Plugin extends LCPlugin {
    constructor() {
        super()
    }
    message(context, _this) {
        let runtimeValue=require('./../jsonDb/runtimeValues.json')
        console.log(context)
        _this.SenseFilter(context.content).then(res=>{
            if(res.errcode !== 87014&&context.from!=_this.ServerQQ){
            }else{
                _this.revoke({
                    groupId:context.fromGroup,
                    msgSeq:context.msgId,
                    msgRandom:context.msgRandom
                })
                let violation=runtimeValue.violation||{}
                let group=violation.group||{};
                let user=group[context.memberId]||{};
                runtimeValue={
                    ...runtimeValue,
                    violation:{
                        ...violation,
                        group:{
                            ...group,
                            [context.memberId]:{
                                ...user,
                                violationCount:user.violationCount?user.violationCount++:1
                            }
                        }
                    }
                }
                if(runtimeValue.violation.group[context.memberId].violationCount>3){
                }else{
                    _this.sendMsg({
                        toUser:context.fromGroup,
                        content:'检测到敏感词，已尝试撤回对应消息,相关用户已被记录，',
                        sendToType:2
                    })
                }
                _this.utils.saveToFile('../jsonDb/runtimeValues.json',runtimeValue)
            }
        })
    }

    event(event, _this) {
        switch (event.EventName) {
            case 'ON_EVENT_GROUP_JOIN': {
                _this.sendMsg({
                    content: `欢迎${event.EventData.UserName}`,
                    to: parseInt(event.EventMsg.FromUin),
                    type: 2
                });
                break;

            }
            default:{
                break;
            }
        }
    }
}

exports.plugin = new Plugin();